package com.ces.knacky.restws.service;

import java.util.Iterator;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ces.knacky.framework.model.IEntity;
import com.ces.knacky.model.Item;
import com.ces.knacky.model.OrderItem;
import com.ces.knacky.services.CheckoutService;

@Path("checkoutService")
@Component
public class CheckoutRService {
	
	@Autowired
	private CheckoutService checkoutService;
	
	@POST
	@Produces(MediaType.TEXT_PLAIN)
	@Path("{ids}")
	public String placeOrder(@PathParam("ids") String itemIds)
	{
		
		System.out.println("Ids: " + itemIds);
		checkoutService.placeOrder(itemIds);
		
		return "Order Placed";
	}
	
	@GET
	@Produces({MediaType.APPLICATION_XML ,MediaType.APPLICATION_JSON})
	@Path("{username}/{orderId}")
	public List<OrderItem> fetchPlacedOrder(@PathParam("username") String username, @PathParam("orderId") Integer orderId)
	{
		List<OrderItem> looi = (List<OrderItem>) checkoutService.fetchPlacedOrder( username, orderId);
		
		return looi;
	}
	
	

}
